<template>
    <div>
        <div id="wangeditor">
            <div ref="editorElem" style="text-align:left;"></div>
        </div>
        <el-button @click="sure">确定</el-button>
    </div>
</template>
<script>
import E from "wangeditor"

export default {
    name: "Editor",
    data () {
        return {
            editor: null,
            editorContent: ''
        };
    },
    mounted () {
        this.editor = new E(document.getElementById('wangeditor'));
        this.editor.config.height = 500;
        this.editor.config.pasteIgnoreImg = true; //忽略粘贴过来的图片
        // this.editor.config.uploadImgServer = '/upload-img'; // 配置 server 接口地址
        this.editor.config.uploadImgAccept = ['jpg', 'jpeg', 'png', 'gif', 'bmp']; // 限制类型
        this.editor.config.uploadImgMaxLength = 5; // 一次最多上传 5 个图片
        this.editor.config.uploadImgMaxSize = 2 * 1024 * 1024; // 2M (默认限制图片大小是 5M ，可以自己修改)
		this.editor.config.uploadImgShowBase64 = true;
        // this.editor.config.uploadImgParams = { //上传图片时可自定义传递一些参数，例如传递验证的 token 等。参数会被添加到 formData 中，一起上传到服务端。
        //     token: 'xxxxx',
        // };
        this.editor.config.showLinkImg = false; //隐藏插入网络图片的功能，即只保留上传本地图片。

        this.editor.create();
    },
    beforeDestroy () {
        // 销毁编辑器
        this.editor.destroy()
        this.editor = null
    },
    methods: {
        sure() {
            console.log(this.editor.txt.html())
        }
    }
}
</script>